package database;

import java.sql.CallableStatement;
import java.sql.SQLException;
import java.sql.Types;

import clientMain.Login;

public class SSDelegate {

	/**
	 * @author Tidus
	 * @param monthYear
	 * @param emId
	 * @return true if no exist, false if exist
	 */
	public boolean checkExistEMSS(String monthYear, String emId){
		try {
			int result;
			Login.conn.setAutoCommit(false);
			CallableStatement cst = Login.conn.prepareCall("{call sp_CheckSS_Em(?,?,?)}");
            cst.setString(1, monthYear);
            cst.setString(2, emId);
            //	Lay bien tra ve cua Procedure trong SQL
            cst.registerOutParameter(3, Types.INTEGER);            
            cst.executeUpdate();
            Login.conn.commit();
            result = cst.getInt(3);
            if(result == 0){
            	return true;
            }else return false;
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public boolean calculateSS(String start, String end, String monthYear, 
									String emId, int contractId, int sbId, boolean action){
		boolean flag = true;
		try {
			Login.conn.setAutoCommit(false);
			CallableStatement cst = Login.conn.prepareCall("{call sp_TotalDaysWork_SalaryInMonth(?,?,?,?,?,?,?)}");
			cst.setString(1, start);
			cst.setString(2, end);
			cst.setString(3, monthYear);
			cst.setString(4, emId);
			cst.setInt(5, contractId);
			cst.setInt(6, sbId);
			cst.setBoolean(7, action);
			cst.executeUpdate();
		} catch (SQLException e) {
			flag = false;
			e.printStackTrace();
		}
		return flag;
	}
	
}
